package com.minyifang.wcspf.work.ui.home.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.home.model.StoreListBean;
import com.minyifang.wcspf.work.ui.home.view.ChooseStoreView;
import com.minyifang.wcspf.work.ui.home.view.SearchView;
import com.minyifang.wcspf.work.ui.home.view.TakeGoodsView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class ChooseStorePresenter extends BasePresenter<ChooseStoreView> {
    public void getStoreList(String longitude, String latitude) {
        Map<String, Object> map = new HashMap<>();
        map.put("x", longitude);
        map.put("y", latitude);
        JSONObject jsonData = Constants.getJsonData(map, null);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getStoreList(requestBody), respond -> getView().showStoreList(respond));
    }

    public void saveStore(String id, String name) {
        this.storeId = id;
        this.storeName = name;
        Map<String, Object> map = new HashMap<>();
        map.put("storeId", id);
        JSONObject jsonData = Constants.getJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().saveStore(requestBody), httpRespond -> getView().showSaveStoreRes(httpRespond));
    }



    private String storeId;
    private String storeName;

    public String getStoreId() {
        return storeId;
    }

    public String getStoreName() {
        return storeName;
    }
}
